﻿Namespace Save

    ''' <summary>
    ''' 保存コマンド作成クラス
    ''' </summary>
    ''' <remarks></remarks>
    Public Class SaveCommandFactory

        Public Shared Property CreateInsertCommand() As Func(Of SaveDefinition, IDbTransaction, String, IDbCommand) = AddressOf InsertCommandFactory.Create

        Public Shared Property CreateUpdateCommand() As Func(Of SaveDefinition, IDbTransaction, String, IDbCommand) = AddressOf UpdateCommandFactory.Create

        Public Shared Property CreateDeleteCommand() As Func(Of SaveDefinition, IDbTransaction, String, IDbCommand) = AddressOf DeleteCommandFactory.Create

        ''' <summary>
        ''' 保存コマンドを作成します。
        ''' </summary>
        ''' <param name="def"></param>
        ''' <param name="trn"></param>
        ''' <param name="prefix"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function Create(ByVal def As SaveDefinition, ByVal trn As IDbTransaction, ByVal prefix As String) As IDbCommand
            Dim saveCommand As IDbCommand = Nothing

            Select Case def.SaveType
                Case SaveType.Create
                    saveCommand = CreateInsertCommand.Invoke(def, trn, prefix)
                Case SaveType.Update
                    saveCommand = CreateUpdateCommand.Invoke(def, trn, prefix)
                Case SaveType.Delete
                    saveCommand = CreateDeleteCommand.Invoke(def, trn, prefix)
                Case Else
                    Throw New NotSupportedException
            End Select

            Return saveCommand
        End Function

    End Class

End Namespace
